package com.zzyl.common.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zsh
 * @version 1.0
 * @since 2025-08-16 18:04
 */
@Component
public class AIModelInvoker {
    @Autowired
    private BaiduAIProperties baiduAiProperties;
    /*
     * 调用百度千帆模型
     * */
    public String qianfanInvoker (String prompt) {
        Qianfan qianfan = new Qianfan(baiduAiProperties.getAccessKey(), baiduAiProperties.getSecretKey());
        // 指定模型
        ChatResponse resp = qianfan.chatCompletion()
                .model(baiduAiProperties.getQianfanModel())
                .temperature(0.6)
                .maxOutputTokens(2048)
                .responseFormat("json_object")
                .addMessage("user", prompt)
                .execute();
        return resp.getResult();
    }
}